package mercurius.fitness.client.rb.summary.forms;

import java.util.HashMap;

import mercurius.fitness.client.rb.summary.Summary;
import mercurius.fitness.client.util.AbstractResponseCommand;
import mercurius.fitness.client.util.MercuriusHelper;
import net.pleso.framework.client.bl.forms.IViewForm;
import net.pleso.framework.client.bl.forms.items.IFormItemsGroup;

import com.google.gwt.user.client.rpc.AsyncCallback;

public class ViewSummaryForm extends SummaryForm implements IViewForm {

	public ViewSummaryForm() {
	}

	public void GetData(final AsyncCallback callback) {
		

		AbstractResponseCommand pass = new AbstractResponseCommand() {

			public void execute() {

			}

			public Object getObject() {
				return new Integer(1);
			}

			public void setObject(Object obj) {

				HashMap m = (HashMap) obj;
				HashMap thisweek = new HashMap();
				HashMap lastweek = new HashMap();

				thisweek.put("duration", (String) m.get("durationThis"));
				thisweek.put("distance", (String) m.get("distanceThis"));
				thisweek.put("activities", (String) m.get("activitiesThis"));
				thisweek.put("totalpoints", new Integer(Integer.parseInt((String) m.get("totalpointsThis"))));
				thisweek.put("calories", new Integer(Integer.parseInt((String) m.get("caloriesThis"))));

				lastweek.put("duration", (String) m.get("durationLast"));
				lastweek.put("distance", (String) m.get("distanceLast"));
				lastweek.put("activities", (String) m.get("activitiesLast"));
				lastweek.put("totalpoints", new Integer(Integer.parseInt((String) m.get("totalpointsLast"))));
				lastweek.put("calories", new Integer(Integer.parseInt((String) m.get("caloriesLast"))));

				thisweek.put("z1", (String) m.get("z1This"));
				thisweek.put("z2", (String) m.get("z2This"));
				thisweek.put("z3", (String) m.get("z3This"));
				thisweek.put("z4", (String) m.get("z4This"));
				thisweek.put("z5", (String) m.get("z5This"));

				lastweek.put("z1", (String) m.get("z1Last"));
				lastweek.put("z2", (String) m.get("z2Last"));
				lastweek.put("z3", (String) m.get("z3Last"));
				lastweek.put("z4", (String) m.get("z4Last"));
				lastweek.put("z5", (String) m.get("z5Last"));
				
				callback.onSuccess(new Summary(thisweek,lastweek));
				
			}
		};

		MercuriusHelper.updateMercurius(new Summary(),
				MercuriusHelper.MERCURIUS_SELECT_BY_ID, callback, pass);
	}

	public String getCaption() {
		return "General Summary";
	}

	public IFormItemsGroup[] getGroups() {
		return groups;
	}

}
